24 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define D(x) cout << #x " is " << x << endl
28 const double EPS
= 1e-9;
29 int cmp(double x
, double y
= 0, double tol
= EPS
) {
30 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
33 const int MAXN
= 1000005;
40 while (getline(cin
, a
) and getline(cin
, b
)) {
47 string s1
= a
; reverse(s1
.begin(), s1
.end()); s1
+= '\n' + b
;
48 string s2
= b
+ '\n' + a
;
53 // Find prefix function of a^r$b
55 for (int i
= 1; i
< 2 * n
+ 1; ++i
) {
57 while (k
> 0 and s1
[i
] != s1
[k
]) k
= p
[k
- 1];
58 if (s1
[i
] == s1
[k
]) k
++;
62 // Find z function of b$a
64 for (int i
= 1, l
= 0, r
= 0; i
< 2 * n
+ 1; ++i
) {
66 if (i
<= r
) z
[i
] = min(z
[i
- l
], r
- i
+ 1);
67 while (i
+ z
[i
] < 2 * n
+ 1 && s2
[z
[i
]] == s2
[i
+ z
[i
]]) ++z
[i
];
68 if (i
+ z
[i
] - 1 > r
) {
74 int ans_i
= -1, ans_j
= -1;
75 for (int i
= 0; i
< n
; ++i
) {
76 if (a
[i
] != b
[n
- i
- 1]) break;
77 int len
= p
[2 * n
- 1 - i
]; // Length of s[j, n-1]^r
78 if (len
== 0) continue;
79 if (z
[n
+ 1 + i
+ 1] >= n
- len
- i
- 1) {
80 ans_i
= i
, ans_j
= n
- len
;
83 printf("%d %d\n", ans_i
, ans_j
);